package cn.smxy.admin.controller;

import cn.smxy.admin.service.CategoryService;
import cn.smxy.param.FamilyFuzzyParam;
import cn.smxy.param.PageParam;
import cn.smxy.pojo.Category;
import cn.smxy.pojo.PlantFamily;
import cn.smxy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 添加种群
     * @param category 种群实体类
     * @return
     */
    @PostMapping("/add")
    public R add(Category category){
        return categoryService.add(category);
    }

    /**
     * 分页查看种群列表
     * @param pageParam
     * @return
     */
    @GetMapping("/page")
    public R page(PageParam pageParam){
        return categoryService.page(pageParam);
    }

    /**
     * 修改种群
     * @param category
     * @return
     */
    @PostMapping("/update")
    public R update(Category category){
        return categoryService.update(category);
    }

    /**
     * 删除种群
     * @param categoryId
     * @return
     */
    @PostMapping("/remove/{categoryId}")
    public R remove(@PathVariable Long categoryId){
        return categoryService.remove(categoryId);
    }

    /**
     * 按条件分页查询科属接口
     * @param familyFuzzyParam 种群id 科属id 分页参数 模糊查询科属名
     * @return
     */
    @PostMapping("/fuzzy")
    public R fuzzy(FamilyFuzzyParam familyFuzzyParam){
        return categoryService.fuzzy(familyFuzzyParam);
    }

    /**
     * 返回科名列表接口
     * @param categoryId 种群id
     * @return
     */
    @GetMapping("/show/{categoryId}")
    public R show(@PathVariable("categoryId") Long categoryId){
        return categoryService.show(categoryId);
    }

    /**
     * 删除科属
     * @param familyId
     * @return
     */
    @PostMapping("/family/remove/{familyId}")
    public R familyRemove(@PathVariable Long familyId){
        return categoryService.familyRemove(familyId);
    }

    /**
     * 添加科名接口
     *
     * @param plantFamily 科属实体类
     * @return
     */
    @PostMapping("/family/add")
    public R addFamily(PlantFamily plantFamily){
        return categoryService.addFamily(plantFamily);
    }

    /**
     * 添加属名接口
     *
     * @param plantFamily 科属实体类
     * @return
     */
    @PostMapping("/family/add/genus")
    public R addGenus(PlantFamily plantFamily){
        return categoryService.addGenus(plantFamily);
    }

    /**
     * 返回属名列表接口
     *
     * @param familyId 科属id
     * @return
     */
    @GetMapping("/family/show/genus/{familyId}")
    public R genusShow(@PathVariable("familyId") Long familyId){
        return categoryService.genusShow(familyId);
    }
}
